package ink.lovejinhu.leetcode;

import org.junit.Test;

/**
 * @author jinhu
 * created 2021-05-06 18:40
 */
public class Solution_0070 {
    public int climbStairs1(int n) {
        if (n == 2) {
            return 2;
        }
        if (n == 1) {
            return 1;
        }
        return climbStairs1(n - 1) + climbStairs1(n - 2);
    }

    @Test
    public void test() {
        int range = 3;
        int i = this.climbStairs(3);
        System.out.println(i);
    }

    public int climbStairs(int n) {
        if (n == 2) {
            return 2;
        }
        if (n == 1) {
            return 1;
        }
        int[] res = new int[n + 1];
        res[0] = 0;
        res[1] = 1;
        res[2] = 2;
        for (int i = 3; i <= n; i++) {
            res[i] = res[i - 1] + res[i - 2];
        }
        return res[n];
    }
}
